//                            _ooOoo_  
//                           o8888888o  
//                           88" . "88  
//                           (| -_- |)  
//                            O\ = /O  
//                        ____/`---'\____  
//                      .   ' \\| |// `.  
//                       / \\||| : |||// \  
//                     / _||||| -:- |||||- \  
//                       | | \\\ - /// | |  
//                     | \_| ''\---/'' | |  
//                      \ .-\__ `-` ___/-. /  
//                   ___`. .' /--.--\ `. . __  
//                ."" '< `.___\_<|>_/___.' >'"".  
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |  
//                 \ \ `-. \_ __\ /__ _/ .-` / /  
//         ======`-.____`-.___\_____/___.-`____.-'======  
//                            `=---='  
//  
//         .............................................  
//                  佛祖保佑             永无BUG 
//          佛曰:  
//                  写字楼里写字间，写字间里程序员；  
//                  程序人员写程序，又拿程序换酒钱。  
//                  酒醒只在网上坐，酒醉还来网下眠；  
//                  酒醉酒醒日复日，网上网下年复年。  
//                  但愿老死电脑间，不愿鞠躬老板前；  
//                  奔驰宝马贵者趣，公交自行程序员。  
//                  别人笑我忒疯癫，我笑自己命太贱；  
//                  不见满街漂亮妹，哪个归得程序员？  


#include "ResSelfKungfuBackMessage.h"

const int ResSelfKungfuBackMessage::_ID = 107206;

ResSelfKungfuBackMessage::ResSelfKungfuBackMessage(){
}
ResSelfKungfuBackMessage::~ResSelfKungfuBackMessage()
{
reset();
}

/**
 * 读取字节缓存
 */
bool ResSelfKungfuBackMessage::read_from(ByteBuf& buf)
{
	//已学习的所有自学武功技能
	short selfKungfuInfos_length = readInt16(buf);
	for (int i = 0; i < selfKungfuInfos_length; i++) {
		auto bean =new SelfKungfuInfo();
		readBean(buf, *bean);
		selfKungfuInfos.push_back(bean);
	}
	//门派格子
	short mengpaiGrid_length = readInt16(buf);
	for (int i = 0; i < mengpaiGrid_length; i++) {
		auto bean =new KungfuGrid();
		readBean(buf, *bean);
		mengpaiGrid.push_back(bean);
	}
	//江湖格子
	short jianghuGrid_length = readInt16(buf);
	for (int i = 0; i < jianghuGrid_length; i++) {
		auto bean =new KungfuGrid();
		readBean(buf, *bean);
		jianghuGrid.push_back(bean);
	}
	
	return true;
}

/**
 * 写入字节缓存
 */
bool ResSelfKungfuBackMessage::write_to(ByteBuf& buf)
{
	//已学习的所有自学武功技能
	writeShort(buf, selfKungfuInfos.size());
	for (int i = 0; i < selfKungfuInfos.size(); i++) {
		writeBean(buf, *selfKungfuInfos[i]);
	}
	//门派格子
	writeShort(buf, mengpaiGrid.size());
	for (int i = 0; i < mengpaiGrid.size(); i++) {
		writeBean(buf, *mengpaiGrid[i]);
	}
	//江湖格子
	writeShort(buf, jianghuGrid.size());
	for (int i = 0; i < jianghuGrid.size(); i++) {
		writeBean(buf, *jianghuGrid[i]);
	}
	
	return true;
}

int ResSelfKungfuBackMessage::getId()
{
  	return _ID;
}



void ResSelfKungfuBackMessage::reset(){
for(auto bean : selfKungfuInfos){
	if (bean)
	delete bean;
}
selfKungfuInfos.clear();
for(auto bean : mengpaiGrid){
	if (bean)
	delete bean;
}
mengpaiGrid.clear();
for(auto bean : jianghuGrid){
	if (bean)
	delete bean;
}
jianghuGrid.clear();
}


ResSelfKungfuBackMessage* ResSelfKungfuBackMessage::clone(){
	auto ret=new ResSelfKungfuBackMessage();
for(auto bean : selfKungfuInfos){
    ret->selfKungfuInfos.push_back(bean->clone());
}
for(auto bean : mengpaiGrid){
    ret->mengpaiGrid.push_back(bean->clone());
}
for(auto bean : jianghuGrid){
    ret->jianghuGrid.push_back(bean->clone());
}
	return ret;
}